package com.example.weather.More;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.weather.R;
import com.example.weather.city_manager.DeleteCityAdapter;
import com.example.weather.data.Person;

import java.util.List;
//显示姓名电话的适配器
public class ContactAdapter extends BaseAdapter {
    Context context;
    List<Person> personList;

    public ContactAdapter(Context context, List<Person> personList) {
        this.context = context;
        this.personList = personList;
    }

    @Override
    public int getCount() {
        return personList.size();
    }

    @Override
    public Object getItem(int i) {
        return personList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ContactAdapter.ViewHolder holder = null;
        View convertView = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_phone,null);
            holder = new ContactAdapter.ViewHolder(convertView);
            convertView.setTag(holder);
        }else{
            holder = (ContactAdapter.ViewHolder) convertView.getTag();
        }
        holder.nv.setText(personList.get(i).getName());
        holder.pv.setText(personList.get(i).getNumber());

        return convertView;
    }
    class ViewHolder{
        TextView pv,nv;
        public ViewHolder(View itemView){
            nv=itemView.findViewById(R.id.item_phone_name);
            pv = itemView.findViewById(R.id.item_phone_number);
        }
    }





























}
